x=1
y=4
# x,y=3,1
#笨方法，先求出x，y对应的二进制形式，然后再比对不同的位置的数量
def OrdToBinary(num):
    if num==0:
        return "0"
    s=""
    while num!=0:
        s=str(num%2)+s
        num=int(num/2)
    return s
def hammingDistance(x,y):
    xStr=OrdToBinary(x)
    yStr=OrdToBinary(y)
    print(xStr,yStr)
    count=0
    xPointer,yPointer=len(xStr)-1,len(yStr)-1
    while xPointer>=0 and yPointer>=0:
        if xStr[xPointer]!=yStr[yPointer]:
            count+=1
        xPointer-=1
        yPointer-=1
    while xPointer>=0:
        if xStr[xPointer]=='1':
            count+=1
        xPointer-=1
    while yPointer>=0:
        if yStr[yPointer]=='1':
            count+=1
        yPointer-=1
    return count

#
def hammingDistance1(x,y):
    diff=x^y  #进行异或运算
    diffStr=str(bin(diff))
    count=0
    for i in diffStr:
        if i=='1':
            count+=1
    return count

print(hammingDistance1(x,y))